home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10857 < prev    next >
Encoding:
Text File  |  1996-08-05  |  791 b   |  34 lines

  1. Path: news.production.compuserve.com!news
  2. From: Tom  <70215.1323@CompuServe.COM>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Calling a function in variable
  5. Date: 20 Mar 1996 14:20:39 GMT
  6. Organization: CompuServe, Inc. (1-800-689-0736)
  7. Message-ID: <4ip47n$591$1@mhadf.production.compuserve.com>
  8. References: <4ikjlq$71@Server2.swix.ch>
  9.  
  10. You can call a function using a pointer variable to a function
  11. by:
  12.  
  13. /*prototype */
  14. void junk_func(void);
  15.  
  16. void main()
  17. {
  18. void (*ptr2func)();             /* define pointer to function */
  19.  
  20. ptr2func = junk_func;           /* assign pointer to function */
  21.  
  22. (*ptrfunc)();                   /* call function */
  23.  
  24. }
  25.  
  26.  
  27. void junk_func(void)
  28.    {
  29.    printf ("This function prints a stupid message\n");
  30.    }
  31.  
  32. Although, this isn't terribly useful, it does show the syntax.
  33. Tom
  34.